package cj.web.tel.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.tel.domain.GroupOffices;

/**
 * 
 * @author 
 *
 */
@DAO
public interface GroupOfficesDAO{
	
	@SQL("SELECT a.*,b.name as depName,c.name as groupName FROM GroupOffices a left join GroupDep b on a.depId=b.id left join GroupInfor c on a.groupId=c.id WHERE a.deleteFlag=1 AND a.groupId=:t.groupId AND a.depId=:t.depId #if(:t.name != null){ AND a.name LIKE '%##(:t.name)%' } ORDER BY a.orderNo,a.updateAt DESC LIMIT :t.start,:t.length ")
    List<GroupOffices> query(@SQLParam("t") GroupOffices groupOffices);
		
	@SQL("SELECT count(1) FROM GroupOffices WHERE deleteFlag=1 AND groupId=:t.groupId AND depId=:t.depId #if(:t.name != null){ AND name LIKE '%##(:t.name)%' } ")
    int querySize(@SQLParam("t") GroupOffices groupOffices);
	
	@SQL("SELECT id,groupId,depId,name FROM GroupOffices WHERE depId=:1 ORDER BY orderNo,updateAt DESC ")
	List<GroupOffices> queryAllById(int depId);
    
    @SQL("select * from GroupOffices where id=:1 ")
    GroupOffices queryById(int id);
    
    @SQL("INSERT INTO GroupOffices ("
			        		+ "groupId,"
			        		+ "depId,"
			        		+ "name,"
			        		+ "duties,"
			        		+ "link,"
			        		+ "orderNo,"
			        		+ "location,"
			        		+ "deleteFlag,"
			        		+ "createUser,"
			        		+ "createAt,"
			        		+ "updateUser,"
			        		+ "updateAt"
							+") VALUES ("
							+ ":t.groupId,"
							+ ":t.depId,"
							+ ":t.name,"
							+ ":t.duties,"
							+ ":t.link,"
							+ ":t.orderNo,"
							+ ":t.location,"
							+ "1,"
							+ ":t.createUser,"
							+ "now(),"
							+ ":t.updateUser,"
							+ "now()"
					+")")
    void create(@SQLParam("t") GroupOffices groupOffices);
	
	@SQL("UPDATE GroupOffices SET "
	    			        + "groupId=:t.groupId,"
	    			        + "depId=:t.depId,"
	    			        + "name=:t.name,"
	    			        + "duties=:t.duties,"
	    			        + "link=:t.link,"
	    			        + "orderNo=:t.orderNo,"
	    			        + "location=:t.location,"
	    			        + "updateUser=:t.updateUser,"
	    			        + "updateAt=now()"
    						+ " WHERE id=:t.id")
    void update(@SQLParam("t") GroupOffices groupOffices);
    
    @SQL("UPDATE GroupOffices SET deleteFlag=0 WHERE id=:1 ")
    void deleteById(int id);
}